package com.wangcang.widgetlibrary.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.wangcang.widgetlibrary.R;
import com.wangcang.widgetlibrary.activity.wxapi.PayActivity;
import com.wangcang.widgetlibrary.chart.ChartActivity;
import com.wangcang.widgetlibrary.face_demo.FaceDemoActivity;
import com.wangcang.widgetlibrary.recording.RecordingPlayActivity;
import com.wangcang.widgetlibrary.share.ShareActivity;

import java.util.LinkedList;

public class WidgetMainActivity extends Activity {

    private Button mBtnId;
    private TextView mDeskTxtId;
    private View mDeskViewId;
    private RecyclerView mDeskRecycleviewId;
    private RelativeLayout mActivityDesk;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_widget_main);
        initView();
    }

    private void initView() {
        mDeskTxtId = (TextView) findViewById(R.id.desk_txt_id);
        mDeskViewId = (View) findViewById(R.id.desk_view_id);
        mDeskRecycleviewId = (RecyclerView) findViewById(R.id.desk_recycleview_id);
        mActivityDesk = (RelativeLayout) findViewById(R.id.activity_desk);

        mDeskRecycleviewId.setLayoutManager(new LinearLayoutManager(this));

        LinkedList<MyBean> list = new LinkedList<>();
        MyBean myBean;

        myBean = new MyBean();
        myBean.setTitle("颜色");
        myBean.setClassName(ColorActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("文字");
        myBean.setClassName(TextShowActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("按钮效果");
        myBean.setClassName(ButtonActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("Label效果");
        myBean.setClassName(LabelActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("时间选择器");
        myBean.setClassName(TimePickActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("弹出式菜单");
        myBean.setClassName(PopupWindowActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("X5内核浏览器");
        myBean.setClassName(X5WebViewActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("多媒体组件");
        myBean.setClassName(MediaActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("通知");
        myBean.setClassName(NotificationActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("弹框");
        myBean.setClassName(DialogActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("录音");
        myBean.setClassName(RecordingPlayActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("自定义键盘");
        myBean.setClassName(KeyboardActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("数字加减器");
        myBean.setClassName(AdderSubtractorActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("分页器");
        myBean.setClassName(DividerActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("通讯录");
        myBean.setClassName(ContactsActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("文字输入");
        myBean.setClassName(TextInputActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("列表");
        myBean.setClassName(ListActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("进度条");
        myBean.setClassName(ProgressbarActivity.class);
        list.add(myBean);


        myBean = new MyBean();
        myBean.setTitle("卡片的样式");
        myBean.setClassName(CardViewActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("滑块");
        myBean.setClassName(SlideBarActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("泡泡弹框");
        myBean.setClassName(BubblePopActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("页面状态切换");
        myBean.setClassName(StateFragmentActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("人脸识别");
        myBean.setClassName(FaceDemoActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("搜索框");
        myBean.setClassName(SearchBoxActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("筛选器");
        myBean.setClassName(FilterActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("开关");
        myBean.setClassName(SwitchButtonActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("蓝牙");
        myBean.setClassName(BluetoothActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("选项卡");
        myBean.setClassName(TabLayoutActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("单选和多选");
        myBean.setClassName(RadioButtonActivity.class);
        list.add(myBean);

//		myBean = new MyBean();
//		myBean.setTitle("多选(二级联动)");
//		myBean.setClassName(MultiSelectActivity.class);
//		list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("一维码/二维码扫描");
        myBean.setClassName(QRCodeActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("图像");
        myBean.setClassName(ImageViewActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("四级地址");
        myBean.setClassName(AddressSelectDemoActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("卡片桌面刷新");
        myBean.setClassName(CardDeskRefreshActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("图表");
        myBean.setClassName(ChartActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("支付");
        myBean.setClassName(PayActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("我的拼卡");
        myBean.setClassName(MyJigsawActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("指纹识别");
        myBean.setClassName(FingerActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("分享的东西");
        myBean.setClassName(ShareActivity.class);
        list.add(myBean);

        myBean = new MyBean();
        myBean.setTitle("叠卡替代方案");
        myBean.setClassName(StackingActivity.class);
        list.add(myBean);

		myBean = new MyBean();
		myBean.setTitle("滑块测试");
		myBean.setClassName(TestSlidebarActivity.class);
		list.add(myBean);

		MyAdapter myAdapter = new MyAdapter(this, list);
        mDeskRecycleviewId.setAdapter(myAdapter);
        myAdapter.notifyDataSetChanged();
    }

    class MyAdapter extends RecyclerView.Adapter {
        private Context context;
        private View view;
        private LinkedList<MyBean> list;

        public MyAdapter(Context context, LinkedList<MyBean> list) {
            this.context = context;
            this.list = list;
        }

        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
            view = LayoutInflater.from(context).inflate(R.layout.demo_show_item_adapter_item, parent, false);
            final MyHolder viewHolder = new MyHolder(view);
            return viewHolder;
        }

        @Override
        public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
            final MyBean myBean = list.get(position);
            ((MyHolder) holder).myTextView.setText(myBean.getTitle());
            ((MyHolder) holder).myRel.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent intent = new Intent();
                    intent.setClass(context, myBean.getClassName());
                    startActivity(intent);
                }
            });
        }

        @Override
        public int getItemCount() {
            if (list == null) {
                return 0;
            } else {
                return list.size();
            }
        }

        class MyHolder extends RecyclerView.ViewHolder {
            private TextView myTextView;
            private RelativeLayout myRel;

            public MyHolder(View itemView) {
                super(itemView);
                myRel = (RelativeLayout) view.findViewById(R.id.desk_adapter_rel);
                myTextView = (TextView) view.findViewById(R.id.desk_adapter_txt_id);
            }
        }
    }

    class MyBean<T> {
        private String title;
        private Class<T> className;

        public String getTitle() {
            return title;
        }

        public void setTitle(String title) {
            this.title = title;
        }

        public Class<T> getClassName() {
            return className;
        }

        public void setClassName(Class<T> className) {
            this.className = className;
        }
    }
}